var base64 = require("../../resources/images/base64.js");

// pages/movies/movies.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    movie_names: [{
        "name": "《蜡笔小新》",
        "style": "刺激"
      },
      {
        "name": "《中国机长》",
        "style": "剧情"
      }
    ],
    index_range: [],
    page_index: 0

  },
  bindChoosePageIndexPicker: function(e) {
    this.setData({
        page_index: String(Number(e.detail.value) + 1)
      }),
      wx.redirectTo({
      url: '../movie_list/movie_list?page_index=' + this.data.page_index,
      })

  },
  onNavigatorTap: function(e) {
    var movie_name = e.currentTarget.dataset.movie_name
    wx.request({
      url: 'http://127.0.0.1:8000/dytt_movies/api/v1.0/service/movie_info',
      method: 'POST',
      data: {
        "movie_name": movie_name
      },
      success: function(res) {
        console.log(res)
        wx.navigateTo({
          url: '../movie_detail/movie_detail?name=' + res.data.data[2],
        })
      }
    })
  },
  updateMovieImages: function() {
    var that = this
    wx.request({
      url: 'http://127.0.0.1:8000/api/v1.0/resource/movie_image',
      method: 'GET',
      success: function(res) {
        that.setData({

          movie_names: res.data
        })
      }
    })

  },
  updateMovieNames: function() {
    var that = this
    wx.request({
      url: 'http://127.0.0.1:8000/api/v1.0/services/movie_info?page=1',
      method: 'GET',
      success: function(res) {
        that.setData({
          movie_names: res.data.movies,
          index_range: res.data.page_info.page_range,
          page_index: res.data.page_info.current_page - 1
        })   
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.updateMovieNames()
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})